package com.hdu.controller.classManagement;

import com.hdu.dto.UserInfoDTO;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.service.IStudentService;
import com.hdu.vo.StudentVo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学生实体类 前端控制器
 * </p>
 *
 * @author xiaobai
 * @since 2024-05-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "学生管理接口")
@RequestMapping("/student")
public class StudentController {

    private final IStudentService studentService;


    @GetMapping
    public Result<PageBean<StudentVo>> page(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "9") Integer limit,
                                            String id, String username, String tID) {
        log.info("分页查询, 参数: {},{},{},{},{}", page, limit, id, username, tID);
        //调用service分页查询
        PageBean<StudentVo> pageBean = studentService.page(page, limit, id, username, tID);
        return Result.success(pageBean);
    }

    @GetMapping("/detail/{id}")
    public Result<UserInfoDTO> detail(@PathVariable String id) {
        log.info("学生查询, id: {}", id);
        return Result.success(studentService.detail(id));
    }

    @DeleteMapping
    public Result<?> delete(@RequestBody List<String> idList) {
        log.info("删除用户, idList:{}", idList);
        studentService.delete(idList);
        return Result.success();
    }


    @PutMapping("/append/{id}/{tID}")
    public Result<?> append(@PathVariable String id, @PathVariable String tID) {
        log.info("新增学生, id,tID: {},{}", id, tID);
        studentService.append(id, tID);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody StudentVo account) {
        log.info("更新角色信息 : {}", account);
        studentService.update(account);
        return Result.success();
    }
}
